package cn.bs.mapper;

import cn.bs.domain.dao.Orders;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface OrderMapper extends BaseMapper<Orders> {

    @Insert("INSERT INTO orders (user_id, canteen_id, seat_id, order_amount, order_date, pay_amount, pay_date, status) " +
            "VALUES (#{userId}, #{canteenId}, #{seatId}, #{orderAmount}, #{orderDate}, #{payAmount}, #{payDate}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insertOrder(Orders orders);

    Orders getById(Integer orderId);

    List<Orders> getByUserId(Integer userId);

    List<Orders> getAll();

    @Select("SELECT * FROM orders order by order_date desc LIMIT #{size} OFFSET #{offset}  ")
    List<Orders> getAllWithPagination(@Param("offset") int offset, @Param("size") int size);

    @Select("SELECT * FROM orders WHERE user_id = #{userId} order by order_date desc LIMIT #{size} OFFSET #{offset}")
    List<Orders> getByUserIdWithPagination(@Param("userId") int userId, @Param("offset") int offset, @Param("size") int size);


    void deleteByUserId(Integer userId);

}
